/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import Negocio.Aluno;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 *
 * @author Jeferson
 */
public class AlunoTableModel implements TableModel{
    
    private ArrayList<Aluno> alunos;
    private ArrayList<TableModelListener> listeners = new ArrayList<TableModelListener>();

    public AlunoTableModel(ArrayList<Aluno> alunos) {
        this.alunos = alunos;
    }
    
    @Override
    public int getRowCount() {
        return alunos.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if(rowIndex<alunos.size()){
            Aluno aln = alunos.get(rowIndex);
            switch (columnIndex){
                case 0: return aln.getFicha();
                case 1: return aln.getNome();
                case 2: return aln.nscmToString();
                case 3: return ""+aln.getPsti()+"-"+aln.getPstf();
                default: return "";
            }
        }
        return "";
    }

    @Override
    public String getColumnName(int column) {
        switch (column){
            case 0: return "Ficha";
            case 1: return "Nome";
            case 2: return "Dt nasc.";
            case 3: return "Pasta";
            default: return "";
        }
    }
    
    public ArrayList<Aluno> getAlunos(){
        return this.alunos;
    }
    
    public void setAlunos(ArrayList<Aluno> alunos){
        this.alunos = alunos;
        for(TableModelListener l : listeners){
            l.tableChanged(null);
        }
        //fireTableDataChanged();
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch(columnIndex){
            case 0: return Integer.class;
            case 2: return Date.class;
            default: return String.class;
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    
    }

    @Override
    public void addTableModelListener(TableModelListener l) {
        if (listeners.contains(l)) {
            return;
        }
        listeners.add(l);
    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
        listeners.remove(l);
    }
    
}
